package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AsysStudentRankRule;
import com.ruoyi.system.service.IAsysStudentRankRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生段位降级规则Controller
 *
 * @author 杨佳霖
 * @date 2025-08-29
 */
@RestController
@RequestMapping("/system/rule")
public class AsysStudentRankRuleController extends BaseController
{
    @Autowired
    private IAsysStudentRankRuleService asysStudentRankRuleService;

    /**
     * 查询学生段位降级规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(AsysStudentRankRule asysStudentRankRule)
    {
        startPage();
        List<AsysStudentRankRule> list = asysStudentRankRuleService.selectAsysStudentRankRuleList(asysStudentRankRule);
        return getDataTable(list);
    }

    /**
     * 导出学生段位降级规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "学生段位降级规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AsysStudentRankRule asysStudentRankRule)
    {
        List<AsysStudentRankRule> list = asysStudentRankRuleService.selectAsysStudentRankRuleList(asysStudentRankRule);
        ExcelUtil<AsysStudentRankRule> util = new ExcelUtil<AsysStudentRankRule>(AsysStudentRankRule.class);
        util.exportExcel(response, list, "学生段位降级规则数据");
    }

    /**
     * 获取学生段位降级规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(asysStudentRankRuleService.selectAsysStudentRankRuleById(id));
    }

    /**
     * 新增学生段位降级规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "学生段位降级规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AsysStudentRankRule asysStudentRankRule)
    {
        return toAjax(asysStudentRankRuleService.insertAsysStudentRankRule(asysStudentRankRule));
    }

    /**
     * 修改学生段位降级规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "学生段位降级规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AsysStudentRankRule asysStudentRankRule)
    {
        return toAjax(asysStudentRankRuleService.updateAsysStudentRankRule(asysStudentRankRule));
    }

    /**
     * 删除学生段位降级规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "学生段位降级规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(asysStudentRankRuleService.deleteAsysStudentRankRuleByIds(ids));
    }
}
